<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="com.uniq.db.ConnectionFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@include file="AdminHeader.jsp"%>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript">
            function submitSource()
            {
                var source=document.getElementById("source").value;
                alert('selected source is '+source);
                document.forms['stock_exchange'].submit();
            }
            
            function exchange()
            {
                alert('submit');
                document.forms['stock_exchange'].action="./Exchange";
                 document.forms['stock_exchange'].submit();
            }
        </script>
        
    </head>
    
    <body>
        
        <form name="stock_exchange">
       
<%
    Connection con=ConnectionFactory.getConnection();
    Statement st=con.createStatement();
            
ResultSet rs1=st.executeQuery("SELECT DISTINCT(supplier) FROM stock ");
out.print("<select name='supplier' >");
while(rs1.next())
       {
    out.println("<option value='"+rs1.getString(1)+"' onclick='submitSource()'>"+rs1.getString(1)+"</option>");
    
       }
out.print("</select>");
    
%>      
            
<%
String supplier=request.getParameter("supplier");
if(supplier!=null)        
        {
    String query="SELECT * from stock where supplier='"+supplier+"'";
    ResultSet rs=st.executeQuery(query);

    out.println("<table style='width:100%'>");
    int c=0;
     out.println("<th>S no</th>");
     out.println("<th>Product Name</th>");
     out.println("<th>Supplier</th>");
     out.println("<th>Article No</th>");
     out.println("<th>QR image Code</th>");
     
     out.println("<th>Current Stock</th>");
     
     
    while(rs.next())
    {
        c++;
       out.println("<tr>");
       out.println("<td align='center'>"+c+"</td>"); 
       out.println("<td align='center'> Product "+ rs.getString("id") +"</td>"); 
       out.println("<td align='center'>"+rs.getString("supplier")+"</td>"); 
       out.println("<td align='center'>"+rs.getString("article_no")+"</td>"); 
       out.println("<td align='center'><img src=DisplayQrCode?id="+rs.getString("id")+"/></td>"); 
       out.println("<td align='center'>"+rs.getString("stock_count")+"</td>"); 
      
       
       out.println("</tr>");
        
    }
     out.println("<table'>");

        }
%>
<input type="submit" value="submit" />
      </form>

    </body>
</html>
